bitkeeper revision 1.1515.1.1 (42922641RfGxKY5iamyIb3lRFjlpzQ)
authorrneugeba@wyvis.research.intel-research.net <rneugeba@wyvis.research.intel-research.net>
Mon, 23 May 2005 18:51:45 +0000 (18:51 +0000)
committerrneugeba@wyvis.research.intel-research.net <rneugeba@wyvis.research.intel-research.net>
Mon, 23 May 2005 18:51:45 +0000 (18:51 +0000)
better support for vnc in qemu device model:
- different ports for different VMs
- allow reverse connect to a running viewer

Signed-off-by: Rolf Neugebauer <rolf.neugebauer@intel.com>
BitKeeper/etc/ignore
tools/ioemu/Makefile
tools/ioemu/target-i386-dm/Makefile
tools/ioemu/target-i386-dm/device-model
tools/ioemu/vl.c
tools/ioemu/vl.h
tools/ioemu/vnc.c
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xm/create.py

index 08995a6ab97c3c33e4faffdcae6a4235ab8552a6..ad45f21a5fd42cfa9e26d27d9ea24e158f3bfd4e 100644 (file)
@@ -149,3 +149,4 @@ xen/tools/figlet/figlet
 xen/xen
 xen/xen-syms
 xen/xen.*
+Makefile.rej
index 9b3157c4c9e294683421eb9b5279e2a37eb117fa..502413fc8a49a2d71c508256d6f818fde68b9b3a 100644 (file)
@@ -42,7 +42,7 @@ distclean: clean
        rm -f config-host.mak config-host.h
        rm -f keysym_adapter_sdl.h keysym_adapter_vnc.h
        for d in $(TARGET_DIRS); do \
-       rm -rf $$d || exit 1 ; \
+       $(MAKE) -C $$d $@ || exit 1 ; \
         done
 
 KEYMAPS=da     en-gb  et  fr     fr-ch  is  lt  modifiers  no  pt-br  sv \
index 300cfed1285609789230eefab0d49def3216c1e8..385f8388002d06d4ce6fd34048f70afc75b73ca3 100644 (file)
@@ -378,6 +378,9 @@ mixeng.o: mixeng.c mixeng.h mixeng_template.h
 clean:
        rm -rf *.o  *.a *~ $(PROGS) gen-op.h opc.h op.h nwfpe slirp qemu-vgaram-bin
 
+distclean:
+       rm -rf *.o  *.a *~ $(PROGS) gen-op.h opc.h op.h nwfpe slirp qemu-vgaram-bin
+
 install: all 
        if [ ! -d $(DESTDIR)$(bindir) ];then mkdir -p $(DESTDIR)$(bindir);fi
        if [ ! -d $(DESTDIR)$(configdir) ];then mkdir -p $(DESTDIR)$(configdir);fi
index b25c175bbcd62ef0766abcf06e99054f8bd68fe4..d5deab7539e900777037559a97e5511a1c7605ac 100755 (executable)
@@ -10,13 +10,22 @@ ulimit -c unlimited
 #gdb --args /usr/sbin/qemu-dm -hda /var/images/qemu-linux.img -nographic \
 #      -serial pty -l 'ioport,int' $*
 
-while getopts ":f:" opt;
+# XXX this is a bit skanky. we assume an order of arguments here.
+# namely to have configfile and vncconnect argument as the first 
+# two arguments.
+
+while getopts ":f:v:d:" opt;
 do
     case $opt in
-      f) QEMUCONFIGFILE=$OPTARG;shift;shift;;
+      f) QEMUCONFIGFILE=$OPTARG;;
+      v) VNCCONNECT=$OPTARG;;
+      d) DOMAIN=$OPTARG;;
       \?) echo;;
     esac
 done
+if [ "x$QEMUCONFIGFILE" != "x" ]; then shift; shift; fi
+if [ "x$VNCCONNECT" != "x" ]; then shift; shift; fi
+
 
 echo $QEMUCONFIGFILE
 if [ ! -z $QEMUCONFIGFILE ];then
@@ -57,6 +66,11 @@ if qemu-dm 2>&1 |grep vnc > /dev/null;then
        elif [ $vnc -eq 1 ];then
                PARMETER="$PARMETER -vnc -k en-us"
        fi
+    VNCPORT=`expr 5900 + $DOMAIN`
+    PARMETER="$PARMETER -vncport $VNCPORT"
+    if [ "x$VNCCONNECT" != "x" ]; then
+        PARMETER="$PARMETER -vncconnect $VNCCONNECT"
+    fi
 fi
 
 #optional cmdline for qemu        
index f6c6e005c002e55f759b845652717ff49679171c..350b76d45122f8b2415ff54d2562e789eb72b093 100644 (file)
@@ -110,6 +110,8 @@ int bios_size;
 static DisplayState display_state;
 int nographic;
 int usevnc; /* 1=vnc only, 2=vnc and sdl */
+long vncport; /* server port */
+const char* vncconnect; /* do a reverse connect to this host*/
 const char* keyboard_layout = 0;
 int64_t ticks_per_sec;
 int boot_device = 'c';
@@ -2098,7 +2100,9 @@ void help(void)
            "-m megs         set virtual RAM size to megs MB [default=%d]\n"
            "-nographic      disable graphical output and redirect serial I/Os to console\n"
 #ifdef CONFIG_VNC
-          "-vnc            use vnc instead of sdl\n"
+          "-vnc port             use vnc instead of sdl\n"
+          "-vncport port         use a different port\n"
+          "-vncconnect host:port do a reverse connect\n"
 #ifdef CONFIG_SDL
           "-vnc-and-sdl    use vnc and sdl simultaneously\n"
 #endif
@@ -2194,6 +2198,8 @@ enum {
     QEMU_OPTION_nographic,
 #ifdef CONFIG_VNC
     QEMU_OPTION_vnc,
+    QEMU_OPTION_vncport,
+    QEMU_OPTION_vncconnect,
 #ifdef CONFIG_SDL
     QEMU_OPTION_vnc_and_sdl,
 #endif
@@ -2258,6 +2264,8 @@ const QEMUOption qemu_options[] = {
     { "nographic", 0, QEMU_OPTION_nographic },
 #ifdef CONFIG_VNC
     { "vnc", 0, QEMU_OPTION_vnc },
+    { "vncport", HAS_ARG, QEMU_OPTION_vncport },
+    { "vncconnect", HAS_ARG, QEMU_OPTION_vncconnect },
 #ifdef CONFIG_SDL
     { "vnc-and-sdl", 0, QEMU_OPTION_vnc_and_sdl },
 #endif
@@ -2370,6 +2378,8 @@ int main(int argc, char **argv)
     snapshot = 0;
     nographic = 0;
     usevnc = 0;
+    vncport=0;
+    vncconnect=NULL;
     kernel_filename = NULL;
     kernel_cmdline = "";
     has_cdrom = 1;
@@ -2464,8 +2474,20 @@ int main(int argc, char **argv)
                 break;
 #ifdef CONFIG_VNC
            case QEMU_OPTION_vnc:
-               usevnc = 1;
-               break;
+            usevnc = 1;
+            break;  
+           case QEMU_OPTION_vncport:
+        {
+            const char *p;
+            p = optarg;
+            vncport= strtol(optarg, (char **)&p, 0);
+        }
+        break;
+           case QEMU_OPTION_vncconnect:
+        {
+            vncconnect=optarg;
+        }
+        break;
 #ifdef CONFIG_SDL
            case QEMU_OPTION_vnc_and_sdl:
                usevnc = 2;
@@ -2852,7 +2874,7 @@ int main(int argc, char **argv)
     } else {
        if (usevnc) {
 #ifdef CONFIG_VNC
-           vnc_display_init(ds, (usevnc==2));
+           vnc_display_init(ds, (usevnc==2), vncport, vncconnect);
 #else
            perror("qemu not configured with vnc support");
 #endif
index 0e1cb9203024890ead2b28c4cba6a99d64ef5536..fcee3da4a7ad2c4d068baaf8079cd65d6a65331c 100644 (file)
@@ -537,7 +537,8 @@ void vga_invalidate_display(void);
 void vga_screen_dump(const char *filename);
 
 /* vnc.c */
-void vnc_display_init(DisplayState *ds, int useAlsoSDL);
+void vnc_display_init(DisplayState *ds, int useAlsoSDL,
+                      long port, const char* connect);
 
 /* cirrus_vga.c */
 void pci_cirrus_vga_init(PCIBus *bus, DisplayState *ds, uint8_t *vga_ram_base, 
index 06601f3f096a58a1498efa0cfb18dff7effca604..24c397dcc531257b16bb792bfd79a99228d5e2dc 100644 (file)
  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
+ *
+ *
+ * reverse connection setup copied from x11vnc.c
+ * Copyright (c) 2002-2005 Karl J. Runge <runge@karlrunge.com>
+ * All rights reserved.
+ * based on:
+ *       the originial x11vnc.c in libvncserver (Johannes E. Schindelin)
+ *       x0rfbserver, the original native X vnc server (Jens Wagner)
+ *       krfb, the KDE desktopsharing project (Tim Jansen)
  */
 #include "vl.h"
 
@@ -447,8 +456,15 @@ static void vnc_cleanup(void)
        rfbScreenCleanup(screen);
 }
 
-void vnc_display_init(DisplayState *ds, int useAlsoSDL)
+
+void vnc_display_init(DisplayState *ds, int useAlsoSDL,
+                      long port, const char* connect)
 {
+    int   len, rport = 5500;
+    char  host[1024];
+    char *p;
+    rfbClientPtr cl;
+    
        if(!keyboard_layout) {
                fprintf(stderr, "No keyboard language specified\n");
                exit(1);
@@ -460,6 +476,7 @@ void vnc_display_init(DisplayState *ds, int useAlsoSDL)
                exit(1);
        }
 
+
        mouse_magic=init_mouse_magic();
        register_savevm("vnc", 0, 1, vnc_save, vnc_load, mouse_magic);
 
@@ -470,6 +487,7 @@ void vnc_display_init(DisplayState *ds, int useAlsoSDL)
                exit(1);
        }
 
+
        screen->serverFormat.redShift = 11;
        screen->serverFormat.greenShift = 5;
        screen->serverFormat.blueShift = 0;
@@ -477,6 +495,11 @@ void vnc_display_init(DisplayState *ds, int useAlsoSDL)
        screen->serverFormat.greenMax = 63;
        screen->serverFormat.blueMax = 31;
 
+    if (port != 0) 
+        screen->port = port;
+    else
+        screen->autoPort = TRUE;
+
        if(useAlsoSDL) {
                ds_sdl=(DisplayState*)malloc(sizeof(DisplayState));
                sdl_display_init(ds_sdl,0);
@@ -496,6 +519,31 @@ void vnc_display_init(DisplayState *ds, int useAlsoSDL)
        ds->dpy_resize = vnc_resize;
        ds->dpy_refresh = vnc_refresh;
 
+    /* deal with reverse connections */
+    if ( connect == NULL || (len = strlen(connect)) < 1) {
+        return;
+    }
+    if ( len > 1024 ) {
+        fprintf(stderr, "vnc reverse connect name too long\n");
+               exit(1);
+    }
+    strncpy(host, connect, len);
+    host[len] = '\0';
+    /* extract port, if any */
+    if ((p = strchr(host, ':')) != NULL) {
+        rport = atoi(p+1);
+        *p = '\0';
+    }
+    cl = rfbReverseConnection(screen, host, rport);
+    if (cl == NULL) {
+        fprintf(stderr, "reverse_connect: %s failed\n", connect);
+    } else {
+        fprintf(stderr, "reverse_connect: %s/%s OK\n", connect, cl->host);
+    }
+
        atexit(vnc_cleanup);
+
+
+
 }
 
index e87f8d32114155cced0a9be4e8b0061f034a9576..d7762fe9162dac00e828a705ce82aeff2ccea99b 100644 (file)
@@ -724,6 +724,7 @@ class XendDomainInfo:
         if self.blkif_backend: flags |= SIF_BLK_BE_DOMAIN
         #todo generalise this
         if ostype == "vmx":
+            log.debug('building vmx domain')            
             err = buildfn(dom            = dom,
                           image          = kernel,
                           control_evtchn = 0,
@@ -733,7 +734,7 @@ class XendDomainInfo:
                           ramdisk        = ramdisk,
                           flags          = flags)
         else:
-            log.warning('building dom with %d vcpus', self.vcpus)
+            log.debug('building dom with %d vcpus', self.vcpus)
             err = buildfn(dom            = dom,
                           image          = kernel,
                           control_evtchn = self.channel.getRemotePort(),
@@ -819,10 +820,25 @@ class XendDomainInfo:
         memory = sxp.child_value(self.config, "memory")
         # Create an event channel
         device_channel = channel.eventChannel(0, self.dom)
+        # see if a vncviewer was specified
+        # XXX RN: bit of a hack. should unify this, maybe stick in config space
+        vncconnect=""
+        image = sxp.child_value(self.config, "image")
+        args = sxp.child_value(image, "args")
+        if args:
+            arg_list = string.split(args)
+            for arg in arg_list:
+                al = string.split(arg, '=')
+                if al[0] == "VNC_VIEWER":
+                    vncconnect=" -v %s" % al[1]
+                    break
+
         # Execute device model.
         #todo: Error handling
+        # XXX RN: note that the order of args matter!
         os.system(device_model
                   + " -f %s" % device_config
+                  + vncconnect
                   + " -d %d" % self.dom
                   + " -p %d" % device_channel['port1']
                   + " -m %s" % memory)
@@ -1158,6 +1174,7 @@ def vm_image_plan9(vm, image):
     if args:
         cmdline += " " + args
     ramdisk = sxp.child_value(image, "ramdisk", '')
+    log.debug("creating plan9 domain with cmdline: %s" %(cmdline,))
     vm.create_domain("plan9", kernel, ramdisk, cmdline)
     return vm
     
@@ -1185,6 +1202,7 @@ def vm_image_vmx(vm, image):
     memmap = sxp.parse(open(memmap))[0]
     from xen.util.memmap import memmap_parse
     memmap = memmap_parse(memmap)
+    log.debug("creating vmx domain with cmdline: %s" %(cmdline,))
     vm.create_domain("vmx", kernel, ramdisk, cmdline, memmap)
     return vm
 
index d6bad1cc62443ad3b85fd19f5ffdf8724ffb2d47..23001cc45859b87ebf498fc7d364bc423778621b 100644 (file)
@@ -532,7 +532,8 @@ def choose_vnc_display():
     return None
 
 def spawn_vnc(display):
-    os.system("vncviewer -listen %d &" % display)
+    os.system("vncviewer -log *:stdout:0 -listen %d &" %
+              (VNC_BASE_PORT + display))
     return VNC_BASE_PORT + display
     
 def preprocess_vnc(opts, vals):